home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Presentations / Presentations ’96 / Sessions ’96 / MacOS 8 Sessions / MacOS 8 Extensions / Demo Patch Code / DemoPatchFromJoanna.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  1.8 KB  |  92 lines  |  [TEXT/CWIE]

  1.  
  2.  
  3.  
  4. #include            <Types.h>
  5. #include            <Patches.h>
  6. #include            <CodeFragments.h>
  7. #include            <Sound.h>
  8.  
  9. void MySysBeepPatch(SInt16 duration);
  10. void DoSomePreprocessing(void);
  11. void DoSomePostprocessing(void);
  12.  
  13. enum {
  14.     kMyPatchCount    =    1        /* Number of patches in my list */
  15. };
  16.  
  17. /* One patch description per patch */
  18. PatchDescription     gSysBeepPatchDescription = {
  19.     &SysBeep,
  20.     &MySysBeepPatch,
  21.     {'wild',
  22.         'demo'},
  23.         {
  24.             kNilOptions,
  25.             { kDoNotMatchAnyOrderedItemService,
  26.                  kDoNotMatchAnyOrderedItemSignature},
  27.             { kDoNotMatchAnyOrderedItemService,
  28.                  kDoNotMatchAnyOrderedItemSignature}
  29.         },
  30.     kPatchEnabledMask,
  31.     paramErr,
  32.     kInvalidID,
  33.     NULL,
  34.     kInvalidID
  35. };
  36.  
  37. /* The table with the list of patch descriptions; this one includes
  38.     only one patch */
  39. PatchDescription *     gPatchDescriptionList[kMyPatchCount] = {
  40.                                 &gSysBeepPatchDescription    };                            
  41.  
  42. /* The Patch header. This is exported as the patch fragment's main entry point. */
  43. PatchHeader gPatchData =     
  44.     {    
  45.         kPatchHeaderTag,
  46.         kPatchHeaderVersion,
  47.         kNilOptions,
  48.         kMyPatchCount,
  49.         &gPatchDescriptionList[0]
  50.     };
  51.  
  52.  
  53.  
  54. /* Do some preprocessing here */ 
  55. void DoSomePreprocessing(void)
  56. {
  57. /*    Put preprocessing code here */
  58.     Debugger();
  59. }
  60.  
  61. void DoSomePostprocessing(void)
  62. {
  63. /*    Put postprocessing code here */
  64.     Debugger();
  65. }
  66.  
  67. typedef void (*SysBeepPatchProcPtr)(SInt16 duration);
  68.  
  69. /*    The patch itself.
  70.     Does some preprocessing, 
  71.     calls through the rest of the patch chain, and
  72.     then does some postprocessing. */
  73. void MySysBeepPatch(SInt16 duration)
  74. {    DoSomePreprocessing();
  75.     
  76. /* Call the routine that handles the chaining*/
  77.     (* (SysBeepPatchProcPtr)     
  78.         gSysBeepPatchDescription.thisCallThroughProc) (duration);
  79.     
  80.     DoSomePostprocessing();
  81.     
  82.     return;
  83. }
  84.  
  85. /* CFM init routine.
  86.     Do not proceed if the patch could not be installed. */
  87.  
  88. OSErr InitMyPatch(const CFragInitBlock *initBlock)
  89. {
  90.     return (gSysBeepPatchDescription.installResult);
  91. }
  92.